
const fs = require("fs")

// 读取文件
exports.readHtmlFiles = function (path, req, res) {

    fs.readFile(path, "utf8", (err, data) => {
        if (err) throw err;
        res.writeHead(200, { 'content-Type': 'text/html;charset=utf8' })
        res.write(data)
        res.end()
    })
}


// 读取JSON文件
exports.readJsonFiles = function (path, req, res) {

    fs.readFile(path, "utf8", (err, data) => {
        if (err) throw err;
        res.writeHead(200, { 'content-Type': 'application/json' })

        res.write(data)
        res.end()
    })
}


// 读取图片  图片为二进制存储
exports.readImgFiles = function (path, req, res) {

    fs.readFile(path, "binary", (err, data) => {
        if (err) throw err;
        res.writeHead(200, { 'content-Type': 'image/jpeg' })

        res.write(data, 'binary')
        res.end()
    })
}